package networkRmi;

import java.net.InetAddress;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;

import messages.Message;

/**
 * 
 * Description:
 * It defines all the features that a CommunicationServer has to provide.
 * such as the receiveMessage(Message), send(Message, InetAddress) and
 * pinging function. 
 *
 */
public interface CommunicationServerRemoteAPI extends Remote {

	/**
	 * Receives the Message 'm' and put it into the queue of 
	 * received messages.
	 * Returns true if no error occurs.
	 * 
	 * @param m
	 * @return done : boolean
	 * @throws RemoteException
	 */
	public boolean receiveMessage(Message m) throws RemoteException;
	
	/**
	 * Sends the Message 'm' to the 'host' machine and lookup for the 
	 * 'service' registered into the 'host' rmiregistry.
	 * Default values for services are the node names.
	 * Returns true if no error occurs.
	 * 
	 * @param m
	 * @param host
	 * @param service
	 * @return done : boolean
	 * @throws RemoteException
	 * @throws NotBoundException
	 */
	public boolean sendMessage(Message m, InetAddress host, String service) 
			throws RemoteException, NotBoundException;
	
	/**
	 * Sends the Message 'm' to the machine 'host' lookup for the
	 * default service name 
	 * (Warning: it's specified by the class implementing this interface).
	 * Returns true if no error occurs.
	 * 
	 * @param m
	 * @param host
	 * @return done : boolean
	 * @throws RemoteException
	 * @throws NotBoundException
	 */
	public boolean sendMessage(Message m, InetAddress host) 
			throws RemoteException, NotBoundException;
	
	/**
	 * Send a 'ping' to the host defined by the NodeDescriptor in input.
	 * Returns true if no error occurs.
	 * @param host : InetAddress
	 * @param service : String
	 * @return reliable : boolean
	 * @throws RemoteException
	 */	
	public boolean ping(InetAddress host, String service) 
			throws RemoteException, NotBoundException;
	
	/**
	 * Returns the answer to a ping remote call.
	 * Returns true if no error occurs.
	 * 
	 * @return reliable : boolean
	 * @throws RemoteException
	 */
	public boolean pingAnswer() throws RemoteException;
	
}
